<template>
  <div id="app">
    <!--<img src="./assets/logo.png">-->
    <!--<router-view></router-view>-->
    <div>
      小浦观影智能取票-采集端
    </div>
    <div style="display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top: 20px;">
      <div style="display: flex; flex-direction: row;">
        <div id="blogId" class="doButton" @click="actionShowImagePicker()"
             style="text-align: center;">
          采集人脸
        </div>
      </div>
    </div>
    <span>{{mytest}}</span>
    <span>{{userFaceUrl}}</span>
    <img id="image-display" :src="userFaceBase64" style="flex: 1; min-height: 300px; width: 100%;"/>
  </div>
</template>

<script>
  import {JNetworkConfig} from 'jbzwebsdk';
  import NativeBridge from './util/NativeBridge';
  import NetworkManager from './util/NetworkManager';
  import StringTool from './tool/StringTool';

  export default {
    name: 'app',
    data: function () {
      return {
        imageUrl: '',
        group: '',
        name: '',
        uid: '',
        userFaceBase64: '',
        mytest: '',
        userFaceUrl: ''
      };
    },
    methods: {
      actionShowImagePicker: function () {
        NativeBridge.defaultManager().getUserFace().then(base64Image => {
          this.mytest = base64Image;
          let saveKey = StringTool.uuidBase64();
          let startTime = Date.now();
          NetworkManager.uploadWithBase64Image(saveKey, base64Image).then(result => {
            let endTime = Date.now();
            let time = endTime - startTime;
            let userFaceUrl = result.userFaceUrl;
            this.userFaceUrl = userFaceUrl;
            window.alert('采集成功:' + userFaceUrl + '\n耗时:' + time + 'ms');
//            window.alert('采集成功');
          }, error => {
            if (error.errorCode === NetworkManager.GetTokenError){
              console.log('获取token失败');
            } else if (error.errorCode === NetworkManager.UploadImageError){
              console.log('上传失败');
            } else {
              console.log('捕获异常失败');
            }
          })
        }, error => {
          window.alert('获取人脸失败' + error);
        });
      },
      uploadImage: function (accessToken) {
      }
    },
    mounted(){
//      console.log(UserFaceBase64);
      JNetworkConfig.setConfig({baseUrl: 'http://180.169.91.75:6600/', timeout: 500000});
    }
  }
</script>

<style>
  .doButton {
    color: #ffffff;
    background-color: #0000ff;
    padding-left: 20px;
    padding-right: 20px;
    line-height: 50px;
    height: 50px;
    text-align: center;
  }

  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>
